# from selenium.webdriver import Chrome
# from selenium.webdriver.chrome.options import Options
#
# chrome_options = Options()
# chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
# # 注意我把chromedriver文件放到了当前文件夹里面，所以可以这样调用
# # 如果你是windows电脑，你需要使用./chromedriver.exe
# driver = Chrome(options=chrome_options)
#
# driver.get('http://exercise.kingname.info/exercise_login_success')
#
#
#
#


import os

import pandas as pd

import requests
from bs4 import BeautifulSoup as Bsoup

import json


def init_data_grab():
    file_name = 'ctrip.html'
    save_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        file_name)
    if not os.path.exists(save_path):
        print('*****not exists the file*****')
        print('开始爬取')
        cookies = {
            'MKT_CKID': '1678877641586.hgzy3.khw3',
            'GUID': '09031061117395115814',
            '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
            '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
            '_bfaStatusPVSend': '1',
            '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
            '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
            '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
            'nfes_isSupportWebP': '1',
            'nfes_isSupportWebP': '1',
            'MKT_Pagesource': 'PC',
            'ibulanguage': 'CN',
            'ibulocale': 'zh_cn',
            'cookiePricesDisplayed': 'CNY',
            'intl_ht1': 'h4=2_445287',
            'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385',
            'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}',
            'Hm_lvt_e4211314613fcf074540918eb10eeecb': '1678877734,1679092404',
            'MKT_CKID_LMT': '1679092404462',
            '_RF1': '169.150.221.195',
            '_pd': '%7B%22r%22%3A1%2C%22_d%22%3A287%2C%22_p%22%3A2%2C%22_o%22%3A43%2C%22s%22%3A333%2C%22_s%22%3A0%7D',
            '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679092399319.3.17.1',
            '_bfs': '1.3',
            '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A3%2C%22pvid%22%3A17%2C%22pid%22%3A0%7D',
            '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679092403922.1679092454756.1679092403922.1679092454756.undefined.0.0.15.15',
            '__zpspc': '9.3.1679092403.1679092454.2%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
            'Hm_lpvt_e4211314613fcf074540918eb10eeecb': '1679092455',
            '_bfi': 'p1%3D0%26p2%3D0%26v1%3D17%26v2%3D16',
            '_bfaStatus': 'success',
        }

        headers = {
            'authority': 'you.ctrip.com',
            'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
            'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
            'cache-control': 'max-age=0',
            # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; nfes_isSupportWebP=1; MKT_Pagesource=PC; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}; Hm_lvt_e4211314613fcf074540918eb10eeecb=1678877734,1679092404; MKT_CKID_LMT=1679092404462; _RF1=169.150.221.195; _pd=%7B%22r%22%3A1%2C%22_d%22%3A287%2C%22_p%22%3A2%2C%22_o%22%3A43%2C%22s%22%3A333%2C%22_s%22%3A0%7D; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679092399319.3.17.1; _bfs=1.3; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A3%2C%22pvid%22%3A17%2C%22pid%22%3A0%7D; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679092403922.1679092454756.1679092403922.1679092454756.undefined.0.0.15.15; __zpspc=9.3.1679092403.1679092454.2%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; Hm_lpvt_e4211314613fcf074540918eb10eeecb=1679092455; _bfi=p1%3D0%26p2%3D0%26v1%3D17%26v2%3D16; _bfaStatus=success',
            'if-none-match': '"26029b-9HI5v9w+uGMzmTwcC400Ziglt+4"',
            'referer': 'https://flights.ctrip.com/',
            'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'document',
            'sec-fetch-mode': 'navigate',
            'sec-fetch-site': 'same-origin',
            'sec-fetch-user': '?1',
            'upgrade-insecure-requests': '1',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
        }
        proxies = {
            'https': '127.0.0.1:7890'
        }
        try:
            response = requests.get('https://you.ctrip.com/', cookies=cookies, headers=headers, proxies=proxies)
        except:
            response = requests.get('https://you.ctrip.com/', cookies=cookies, headers=headers)
        html = response.text

    # part 1
        f = open(save_path, 'a+', encoding='utf-8')
        f.write(html)
        f.close()
    else:
        print('*****Exists the file*****')
        print('文件读取')
        f = open(save_path, 'r', encoding='utf-8')
        html = f.read()
        f.close()

    soup = Bsoup(html, 'html.parser')
    index_div = soup.findAll('div', attrs={'class': 'city-selector-tab-main'})[1]
    city_divs = index_div.findAll('div', attrs={'class': 'city-selector-tab-main-city'})
    to_csv_data = {}
    to_csv_data['title'] = []
    to_csv_data['name'] = []
    to_csv_data['url'] = []
    to_csv_data['url_id'] = []
    print('*****数据处理*****')
    for city_div in city_divs:
        title = city_div.find('div', attrs={'class': 'city-selector-tab-main-city-title'})
        # print('title', title.text)
        aaas = city_div.findAll('a', attrs={'class': 'city-selector-tab-main-city-list-item'})
        for aas in aaas:
            # print('name', aas.text)
            # print('url', aas.get('href'))
            # print('url_id', aas.get('href').split('place')[1].split('.html')[0].replace('/',''))
            to_csv_data['title'].append(title.text)
            to_csv_data['name'].append(aas.text)
            to_csv_data['url'].append(aas.get('href'))
            to_csv_data['url_id'].append(aas.get('href').split('place')[1].split('.html')[0].replace('/',''))
    print('*****数据处理完毕*****')

    to_csv_name = 'ctrip.csv'
    to_csv_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        to_csv_name)
    df = pd.DataFrame(to_csv_data)
    df.to_csv(to_csv_path, index=False)
    print('*****数据保存完毕*****')
    print('*****请到{}领取*****'.format(os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        to_csv_name)))
        # print(index_div)
        # print(index_div.text)

def sight_grab(request_url, pages):
    # pages = 5

    to_csv_data = {}
    to_csv_data['city_id'] = []
    to_csv_data['name'] = []
    to_csv_data['position'] = []
    to_csv_data['ranting'] = []
    to_csv_data['hot'] = []
    to_csv_data['url'] = []
    to_csv_data['img'] = []
    to_csv_data['comment_num'] = []

    for page in range(pages):
        print(page)
        # request_url = 'https://you.ctrip.com/sight/zuogong120405/s0-p{}-i1.html'.format(page + 1)
        file_name = 'sight.html'
        save_path = os.path.join(os.path.abspath(
            os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
            file_name)
        if not os.path.exists(save_path):
            cookies = {
                'MKT_CKID': '1678877641586.hgzy3.khw3',
                'GUID': '09031061117395115814',
                '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
                '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
                '_bfaStatusPVSend': '1',
                '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
                '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
                '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
                'nfes_isSupportWebP': '1',
                'nfes_isSupportWebP': '1',
                'MKT_Pagesource': 'PC',
                'ibulanguage': 'CN',
                'ibulocale': 'zh_cn',
                'cookiePricesDisplayed': 'CNY',
                'intl_ht1': 'h4=2_445287',
                'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385',
                'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}',
                'Hm_lvt_e4211314613fcf074540918eb10eeecb': '1678877734,1679092404',
                'MKT_CKID_LMT': '1679092404462',
                '_RF1': '169.150.221.195',
                'ASP.NET_SessionSvc': 'MTAuNjAuMzUuNDR8OTA5MHxqaW5xaWFvfGRlZmF1bHR8MTY1NjQ2NjI4NjI2MQ',
                '_pd': '%7B%22r%22%3A1%2C%22_d%22%3A243%2C%22_p%22%3A3%2C%22_o%22%3A62%2C%22s%22%3A310%2C%22_s%22%3A1%7D',
                '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679092399319.3.24.1',
                '_bfs': '1.10',
                '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A3%2C%22pvid%22%3A24%2C%22pid%22%3A290546%7D',
                'Hm_lpvt_e4211314613fcf074540918eb10eeecb': '1679096270',
                '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679095354880.1679096272983.1679095354880.1679096272983.undefined.0.0.22.22',
                '__zpspc': '9.3.1679092403.1679096272.9%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
                '_bfi': 'p1%3D290546%26p2%3D290546%26v1%3D24%26v2%3D23',
                '_bfaStatus': 'success',
            }

            headers = {
                'authority': 'you.ctrip.com',
                'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
                'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
                'cache-control': 'max-age=0',
                # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; nfes_isSupportWebP=1; MKT_Pagesource=PC; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}; Hm_lvt_e4211314613fcf074540918eb10eeecb=1678877734,1679092404; MKT_CKID_LMT=1679092404462; _RF1=169.150.221.195; ASP.NET_SessionSvc=MTAuNjAuMzUuNDR8OTA5MHxqaW5xaWFvfGRlZmF1bHR8MTY1NjQ2NjI4NjI2MQ; _pd=%7B%22r%22%3A1%2C%22_d%22%3A243%2C%22_p%22%3A3%2C%22_o%22%3A62%2C%22s%22%3A310%2C%22_s%22%3A1%7D; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679092399319.3.24.1; _bfs=1.10; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A3%2C%22pvid%22%3A24%2C%22pid%22%3A290546%7D; Hm_lpvt_e4211314613fcf074540918eb10eeecb=1679096270; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679095354880.1679096272983.1679095354880.1679096272983.undefined.0.0.22.22; __zpspc=9.3.1679092403.1679096272.9%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; _bfi=p1%3D290546%26p2%3D290546%26v1%3D24%26v2%3D23; _bfaStatus=success',
                'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
                'sec-ch-ua-mobile': '?0',
                'sec-ch-ua-platform': '"Windows"',
                'sec-fetch-dest': 'document',
                'sec-fetch-mode': 'navigate',
                'sec-fetch-site': 'none',
                'sec-fetch-user': '?1',
                'upgrade-insecure-requests': '1',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
            }
            proxies = {
                'https': '127.0.0.1:7890'
            }
            try:
                response = requests.get(request_url, cookies=cookies, headers=headers, proxies=proxies)
            except:
                response = requests.get(request_url, cookies=cookies, headers=headers)
            html = response.text
            f = open(save_path, 'a+', encoding='utf-8')
            f.write(html)
            f.close()
        else:
            print('*****Exists the file*****')
            print('文件读取')
            f = open(save_path, 'r', encoding='utf-8')
            html = f.read()
            f.close()

        soup = Bsoup(html, 'html.parser')
        index_div = soup.find('div', attrs={'class': 'list_wide_mod2'})
        sight_divs = index_div.findAll('div', attrs={'class': 'list_mod2'})

        print('*****数据处理*****')
        for sight_div in sight_divs:
            left_div = sight_div.find('div', attrs={'class': 'leftimg'})
            url = left_div.find('a').get('href')
            img = left_div.find('a').find('img').get('src')
            result_div = sight_div.find('div', attrs={'class': 'rdetailbox'}).find('dl')
            name = result_div.find('a').text
            position = result_div.find('dd', attrs={'class': 'ellipsis'}).text
            hot = result_div.find('b', attrs={'class': 'hot_score_number'}).text
            result_ul = sight_div.find('ul', attrs={'class': 'r_comment'})
            # print(result_ul)
            ranting = result_ul.find('a', attrs={'class':'score'}).find('strong').text
            comment_num = result_ul.find('a', attrs={"rel": 'nofollow'}).text

            to_csv_data['city_id'].append(request_url.split('sight')[1].split('/')[1])

            to_csv_data['name'].append(name)
            print(name, '已加入数据')
            to_csv_data['position'].append(position.replace(' ', '').replace('\n', ''))
            to_csv_data['hot'].append(hot)
            to_csv_data['ranting'].append(ranting)
            to_csv_data['comment_num'].append(comment_num.replace(' ', '').replace('\n', ''))
            to_csv_data['url'].append(url)
            to_csv_data['img'].append(img)
            print('city_id len: ', len(to_csv_data['city_id']))
            print('name len: ', len(to_csv_data['name']))
            print('position len: ', len(to_csv_data['position']))
            print('hot len: ', len(to_csv_data['hot']))
            print('ranting len: ', len(to_csv_data['ranting']))
            print('comment_num len: ', len(to_csv_data['comment_num']))
            print('url len: ', len(to_csv_data['url']))
            print('img len: ', len(to_csv_data['img']))

        # print('*****数据处理完毕*****')
    #
    print(to_csv_data)
    to_csv_name = 'sight.csv'
    to_csv_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        to_csv_name)
    df = pd.DataFrame(to_csv_data)
    df.to_csv(to_csv_path, index=False)
    print('*****数据保存完毕*****')
    print('*****请到{}领取*****'.format(os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        to_csv_name)))

# sight_grab()

def m_sight_basic_data_grab():

    cookies = {
        'MKT_CKID': '1678877641586.hgzy3.khw3',
        'GUID': '09031061117395115814',
        '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
        '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
        '_bfaStatusPVSend': '1',
        '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
        '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
        '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
        'nfes_isSupportWebP': '1',
        'ibulanguage': 'CN',
        'ibulocale': 'zh_cn',
        'cookiePricesDisplayed': 'CNY',
        'intl_ht1': 'h4=2_445287',
        'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385',
        'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}',
        'MKT_CKID_LMT': '1679092404462',
        'librauuid': '',
        '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46',
        '__zpspc': '9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
        '_ga': 'GA1.2.1659888908.1679100096',
        '_gid': 'GA1.2.1082757209.1679100096',
        '_RF1': '106.43.104.164',
        'ibu_h5_lang': 'en',
        'ibu_h5_local': 'en-us',
        'Hm_lvt_37b54c42b9dde393e60c88c1a84657cb': '1679100205',
        'Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb': '1679100629',
        'MKT_Pagesource': 'H5',
        '_bfs': '1.37',
        '_bfi': 'p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50',
        '_bfaStatus': 'success',
        '_pd': '%7B%22_o%22%3A2%2C%22s%22%3A168%2C%22_s%22%3A0%7D',
        '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679101944394.4.103.0',
        '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A4%2C%22pvid%22%3A103%2C%22pid%22%3A%220%22%7D',
    }

    headers = {
        'authority': 'm.ctrip.com',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
        'content-type': 'application/json',
        # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}; MKT_CKID_LMT=1679092404462; librauuid=; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46; __zpspc=9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; _ga=GA1.2.1659888908.1679100096; _gid=GA1.2.1082757209.1679100096; _RF1=106.43.104.164; ibu_h5_lang=en; ibu_h5_local=en-us; Hm_lvt_37b54c42b9dde393e60c88c1a84657cb=1679100205; Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb=1679100629; MKT_Pagesource=H5; _bfs=1.37; _bfi=p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50; _bfaStatus=success; _pd=%7B%22_o%22%3A2%2C%22s%22%3A168%2C%22_s%22%3A0%7D; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679101944394.4.103.0; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A4%2C%22pvid%22%3A103%2C%22pid%22%3A%220%22%7D',
        'cookieorigin': 'https://m.ctrip.com',
        'origin': 'https://m.ctrip.com',
        'referer': 'https://m.ctrip.com/webapp/you/gsdestination/citySelector/citySelector.html?seo=0&districtId=2&isHideNavBar=YES&from=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgsdestination%2Fplace%2F2.html%3Fseo%3D0%26ishideheader%3Dtrue%26%26from%3Dhttps%253a%252f%252fm.ctrip.com%252fwebapp%252fyou%252fgsdestination%252f%253fseo%253d0%2526streetx%253d1%2526ishidenavbar%253dyes%2526from%253d%2526searchcityshowmesssage%253d',
        'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
        'sec-ch-ua-mobile': '?1',
        'sec-ch-ua-platform': '"Android"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36',
    }

    params = {
        '_fxpcqlniredt': '09031061117395115814',
        'x-traceID': '09031061117395115814-1679101944469-7579449',
    }

    json_data = {
        'data': '{"source":"destH5"}',
        'serviceName': 'DestinationCoreService.getStaticDistrictCategoryList',
        'head': {
            'cid': '09031061117395115814',
            'ctok': '',
            'cver': '1.0',
            'lang': '01',
            'sid': '8888',
            'syscode': '09',
            'auth': '',
            'xsid': '',
            'extension': [],
        },
    }

    response = requests.post(
        'https://m.ctrip.com/restapi/soa2/17916/json/invokeOnDemand',
        params=params,
        cookies=cookies,
        headers=headers,
        json=json_data,
    )
    print(json.loads(response.text)['data'])
    json_data = json.loads(json.loads(response.text)['data'])
    all_data = json_data['districtCategoryInChina']
    to_csv_data = {}
    to_csv_data['categoryName'] = []
    to_csv_data['districtId'] = []
    to_csv_data['districtType'] = []
    to_csv_data['districtName'] = []
    to_csv_data['districtEname'] = []
    to_csv_data['isOverSea'] = []
    to_csv_data['h5Url'] = []
    to_csv_data['url'] = []
    to_csv_data['parentName'] = []
    to_csv_data['isHot'] = []
    for data in all_data:
        indexs = data['indexes']
        for index in indexs:
            to_csv_data['categoryName'].append(data['categoryName'])
            to_csv_data['districtId'].append(index['districtId'])
            to_csv_data['districtType'].append(index['districtType'])
            to_csv_data['districtName'].append(index['districtName'])
            to_csv_data['districtEname'].append(index['districtEname'])
            to_csv_data['isOverSea'].append(index['isOverSea'])
            to_csv_data['h5Url'].append(index['h5Url'])
            to_csv_data['url'].append(index['url'])
            to_csv_data['parentName'].append(index['parentName'])
            to_csv_data['isHot'].append(index['isHot'])
    print(to_csv_data)
    to_csv_name = 'basic.csv'
    to_csv_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        to_csv_name)
    df = pd.DataFrame(to_csv_data)
    df.to_csv(to_csv_path, index=False)

# m_sight_data_grab()

def m_sight_index_data_grab(districtId):
    import requests

    cookies = {
        'MKT_CKID': '1678877641586.hgzy3.khw3',
        'GUID': '09031061117395115814',
        '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
        '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
        '_bfaStatusPVSend': '1',
        '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
        '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
        '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
        'nfes_isSupportWebP': '1',
        'ibulanguage': 'CN',
        'ibulocale': 'zh_cn',
        'cookiePricesDisplayed': 'CNY',
        'intl_ht1': 'h4=2_445287',
        'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385',
        'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}',
        'MKT_CKID_LMT': '1679092404462',
        '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46',
        '__zpspc': '9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
        '_ga': 'GA1.2.1659888908.1679100096',
        '_gid': 'GA1.2.1082757209.1679100096',
        'ibu_h5_lang': 'en',
        'ibu_h5_local': 'en-us',
        'Hm_lvt_37b54c42b9dde393e60c88c1a84657cb': '1679100205',
        'MKT_Pagesource': 'H5',
        '_bfi': 'p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50',
        '_bfaStatus': 'success',
        'librauuid': '',
        '_RF1': '169.150.221.195',
        'Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb': '1679127201',
        '_pd': '%7B%22_o%22%3A1%2C%22s%22%3A234%2C%22_s%22%3A0%7D',
        '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679127205051.7.159.214062',
        '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A7%2C%22pvid%22%3A159%2C%22pid%22%3A%22214062%22%7D',
    }

    headers = {
        'authority': 'm.ctrip.com',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
        'content-type': 'application/json',
        # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679092398&Expires=1679697198385; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679092398387&CURL=https%3A%2F%2Fflights.ctrip.com%2Fonline%2Fchannel%2Fdomestic%3Fallianceid%3D4899%26sid%3D155997%26utm_medium%3Dgoogle%26utm_campaign%3Dpp%26utm_source%3Dgoogleppc%26gclid%3DEAIaIQobChMI04uizILk_QIVSQ2tBh2C1whGEAAYASAAEgJ6IvD_BwE%26gclsrc%3Daw.ds%26keywordid%3D2642337343-70570537617&VAL={}; MKT_CKID_LMT=1679092404462; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46; __zpspc=9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; _ga=GA1.2.1659888908.1679100096; _gid=GA1.2.1082757209.1679100096; ibu_h5_lang=en; ibu_h5_local=en-us; Hm_lvt_37b54c42b9dde393e60c88c1a84657cb=1679100205; MKT_Pagesource=H5; _bfi=p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50; _bfaStatus=success; librauuid=; _RF1=169.150.221.195; Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb=1679127201; _pd=%7B%22_o%22%3A1%2C%22s%22%3A234%2C%22_s%22%3A0%7D; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679127205051.7.159.214062; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A7%2C%22pvid%22%3A159%2C%22pid%22%3A%22214062%22%7D',
        'cookieorigin': 'https://m.ctrip.com',
        'origin': 'https://m.ctrip.com',
        'referer': 'https://m.ctrip.com/webapp/you/gspoi/sight/744.html?seo=0&navBarStyle=white&from=https%3A%2F%2Fgs.ctrip.com%2Fhtml5%2Fyou%2Fplace%2F120084.html%3FhideBrandTip%3D1',
        'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
        'sec-ch-ua-mobile': '?1',
        'sec-ch-ua-platform': '"Android"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36',
    }

    params = {
        '_fxpcqlniredt': '09031061117395115814',
        'x-traceID': '09031061117395115814-1679127205465-6430624',
    }

    json_data = {
        'index': 1,
        'count': 10,
        'sortType': 1,
        'isShowAggregation': True,
        'districtId': districtId,
        'scene': 'DISTRICT',
        'pageId': '214062',
        'traceId': 'f8460ef2-a271-1e1f-ef7a-167912238063',
        'extension': [
            {
                'name': 'osVersion',
                'value': '6.0',
            },
            {
                'name': 'deviceType',
                'value': 'android',
            },
        ],
        'filter': {
            'filterItems': [],
        },
        'crnVersion': '2020-09-01 22:00:45',
        'isInitialState': True,
        'head': {
            'cid': '09031061117395115814',
            'ctok': '',
            'cver': '1.0',
            'lang': '01',
            'sid': '8888',
            'syscode': '09',
            'auth': '',
            'xsid': '',
            'extension': [],
        },
    }


    try:
        proxies = {
            'https': '127.0.0.1:7890'
        }
        response = requests.post(
            'https://m.ctrip.com/restapi/soa2/18254/json/getAttractionList',
            params=params,
            cookies=cookies,
            headers=headers,
            json=json_data,
            proxies=proxies
        )

    except:
        response = requests.post(
            'https://m.ctrip.com/restapi/soa2/18254/json/getAttractionList',
            params=params,
            cookies=cookies,
            headers=headers,
            json=json_data,
        )
    html = response.text
    # print(html)
    try:
        json_data = json.loads(html)['attractionList']
    except:
        print('attractionList Error: ', json.loads(html))
        return ''

    # print(json_data)
    to_csv_data = {}
    to_csv_data['poiId'] = []
    to_csv_data['businessId'] = []
    to_csv_data['poiName'] = []
    to_csv_data['commentCount'] = []
    to_csv_data['commentScore'] = []
    to_csv_data['districtId'] = []
    to_csv_data['districtName'] = []
    to_csv_data['sightLevelStr'] = []
    to_csv_data['coverImageUrl'] = []
    to_csv_data['distanceStr'] = []
    to_csv_data['tagNameList'] = []
    to_csv_data['otherTag'] = []
    to_csv_data['detailUrl'] = []
    to_csv_data['price'] = []
    to_csv_data['priceTypeDesc'] = []
    to_csv_data['isFree'] = []
    to_csv_data['openStatus'] = []
    to_csv_data['shortFeatures'] = []
    to_csv_data['sightCategoryInfo'] = []
    to_csv_data['latitude'] = []
    to_csv_data['longitude'] = []
    to_csv_data['heatScore'] = []
    for data in json_data:
        # print(data)
        data = data['card']
        to_csv_data['poiId'].append(data['poiId'])
        to_csv_data['businessId'].append(data['businessId'])
        to_csv_data['poiName'].append(data['poiName'])
        try:
            to_csv_data['commentCount'].append(data['commentCount'])
        except:
            to_csv_data['commentCount'].append('0')
        try:
            to_csv_data['commentScore'].append(data['commentScore'])
        except:
            to_csv_data['commentScore'].append('0.0')

        to_csv_data['districtId'].append(data['districtId'])
        try:
            to_csv_data['districtName'].append(data['districtName'])
        except:
            to_csv_data['districtName'].append('')
        try:
            to_csv_data['sightLevelStr'].append(data['sightLevelStr'])
        except:
            to_csv_data['sightLevelStr'].append('')
        to_csv_data['coverImageUrl'].append(data['coverImageUrl'])
        try:
            to_csv_data['distanceStr'].append(data['distanceStr'])
        except:
            to_csv_data['distanceStr'].append('')
        try:
            to_csv_data['tagNameList'].append(data['tagNameList'])
        except:
            print('Not TagNameList data: ', data)
            to_csv_data['tagNameList'].append([''])

        try:
            to_csv_data['otherTag'].append(data['otherTagList'][0]['name'])
        except:
            to_csv_data['otherTag'].append('')
        to_csv_data['detailUrl'].append(data['detailUrl'])
        try:
            to_csv_data['price'].append(data['price'])
        except:
            to_csv_data['price'].append('free')
        try:
            to_csv_data['priceTypeDesc'].append(data['priceTypeDesc'])
        except:
            to_csv_data['priceTypeDesc'].append('')

        to_csv_data['isFree'].append(data['isFree'])
        try:
            to_csv_data['openStatus'].append(data['openStatus'])
        except:
            to_csv_data['openStatus'].append('')
        try:
            to_csv_data['shortFeatures'].append(data['shortFeatures'])
        except:
            to_csv_data['shortFeatures'].append('')
        try:
            to_csv_data['sightCategoryInfo'].append(data['sightCategoryInfo'])
        except:
            to_csv_data['sightCategoryInfo'].append('')
        to_csv_data['latitude'].append(data['coordinate']['latitude'])
        to_csv_data['longitude'].append(data['coordinate']['longitude'])
        try:
            to_csv_data['heatScore'].append(data['heatScore'])
        except:
            to_csv_data['heatScore'].append('0.0')

    # print(to_csv_data)
    to_csv_name = '{}_sight.csv'.format(districtId)
    to_csv_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data/sight')),
        to_csv_name)
    df = pd.DataFrame(to_csv_data)
    df.to_csv(to_csv_path, index=False)
# m_sight_index_data_grab()

def sigth_data_grab():
    r_csv_name = 'basic.csv'
    r_csv_path = os.path.join(os.path.abspath(
        os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'static/spider/data')),
        r_csv_name)
    r_csv_data = pd.read_csv(r_csv_path)
    df = pd.DataFrame(r_csv_data)
    df_dict = df.to_dict(orient='record')
    for index in range(69, len(df_dict)):
        data = df_dict[index]
        print('index: ', index, 'data: ', data)
        districtId = data['districtId']
        m_sight_index_data_grab(districtId)

# sigth_data_grab()

# def trash_sp():
#     cookies = {
#         'MKT_CKID': '1678877641586.hgzy3.khw3',
#         'GUID': '09031061117395115814',
#         '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
#         '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
#         '_bfaStatusPVSend': '1',
#         '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
#         '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
#         '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
#         'nfes_isSupportWebP': '1',
#         'ibulanguage': 'CN',
#         'ibulocale': 'zh_cn',
#         'cookiePricesDisplayed': 'CNY',
#         'intl_ht1': 'h4=2_445287',
#         'MKT_CKID_LMT': '1679092404462',
#         '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46',
#         '__zpspc': '9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
#         '_ga': 'GA1.2.1659888908.1679100096',
#         '_gid': 'GA1.2.1082757209.1679100096',
#         'ibu_h5_lang': 'en',
#         'ibu_h5_local': 'en-us',
#         'Hm_lvt_37b54c42b9dde393e60c88c1a84657cb': '1679100205',
#         'MKT_Pagesource': 'H5',
#         '_bfi': 'p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50',
#         '_bfaStatus': 'success',
#         '_RF1': '169.150.221.195',
#         'librauuid': '',
#         'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679136388916&CURL=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgspoi%2Fsight%2F18254.html%3FisHideNavBar%3DYES%26seo%3D0%26allianceid%3D4899%26sid%3D155997%26isHideNavBar%3DYES%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fwebapp%252Fyou%252Fgsdestination%252Fplace%252F2.html%253Fseo%253D0%2526ishideheader%253Dtrue%2526secondwakeup%253Dtrue%2526dpclickjump%253Dtrue%2526allianceid%253D4899%2526sid%253D155997%2526from%253Dhttps%25253A%25252F%25252Fm.ctrip.com%25252Fhtml5%25252F&VAL={"h5_vid":"1678877639540.m3gjc"}',
#         'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679136390&Expires=1679741189507',
#         'hotelhst': '1164390341',
#         '_gat': '1',
#         '_pd': '%7B%22_o%22%3A2%2C%22s%22%3A340%2C%22_s%22%3A0%7D',
#         '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679136526457.9.176.214062',
#         '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A9%2C%22pvid%22%3A176%2C%22pid%22%3A214062%7D',
#         'Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb': '1679136528',
#     }
#
#     headers = {
#         'authority': 'm.ctrip.com',
#         'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
#         'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
#         'cache-control': 'max-age=0',
#         # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; MKT_CKID_LMT=1679092404462; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46; __zpspc=9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; _ga=GA1.2.1659888908.1679100096; _gid=GA1.2.1082757209.1679100096; ibu_h5_lang=en; ibu_h5_local=en-us; Hm_lvt_37b54c42b9dde393e60c88c1a84657cb=1679100205; MKT_Pagesource=H5; _bfi=p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50; _bfaStatus=success; _RF1=169.150.221.195; librauuid=; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679136388916&CURL=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgspoi%2Fsight%2F18254.html%3FisHideNavBar%3DYES%26seo%3D0%26allianceid%3D4899%26sid%3D155997%26isHideNavBar%3DYES%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fwebapp%252Fyou%252Fgsdestination%252Fplace%252F2.html%253Fseo%253D0%2526ishideheader%253Dtrue%2526secondwakeup%253Dtrue%2526dpclickjump%253Dtrue%2526allianceid%253D4899%2526sid%253D155997%2526from%253Dhttps%25253A%25252F%25252Fm.ctrip.com%25252Fhtml5%25252F&VAL={"h5_vid":"1678877639540.m3gjc"}; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679136390&Expires=1679741189507; hotelhst=1164390341; _gat=1; _pd=%7B%22_o%22%3A2%2C%22s%22%3A340%2C%22_s%22%3A0%7D; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679136526457.9.176.214062; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A9%2C%22pvid%22%3A176%2C%22pid%22%3A214062%7D; Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb=1679136528',
#         'if-none-match': '"46e1-m7gDmt5Obe3MCcx2ESukXi8uGI4"',
#         'referer': 'https://m.ctrip.com/webapp/you/gsdestination/place/3179.html?ishideheader=true&fromcitylist=yes&seo=0&from=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgsdestination%2Fplace%2F2.html%3Fseo%3D0%26ishideheader%3Dtrue%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fhtml5%252F',
#         'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
#         'sec-ch-ua-mobile': '?1',
#         'sec-ch-ua-platform': '"Android"',
#         'sec-fetch-dest': 'document',
#         'sec-fetch-mode': 'navigate',
#         'sec-fetch-site': 'same-origin',
#         'sec-fetch-user': '?1',
#         'upgrade-insecure-requests': '1',
#         'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36',
#     }
#
#     params = [
#         ('isHideNavBar', 'YES'),
#         ('seo', '0'),
#         ('isHideNavBar', 'YES'),
#         ('from',
#          'https://m.ctrip.com/webapp/you/gsdestination/place/3179.html?ishideheader=true&fromcitylist=yes&seo=0&from=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgsdestination%2Fplace%2F2.html%3Fseo%3D0%26ishideheader%3Dtrue%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fhtml5%252F'),
#     ]
#
#     try:
#         response = requests.get('https://m.ctrip.com/webapp/you/gspoi/sight/3179.html', params=params, cookies=cookies,
#                                 headers=headers)
#     except:
#         proxies = {
#             'https': '127.0.0.1:7890'
#         }
#         response = requests.get('https://m.ctrip.com/webapp/you/gspoi/sight/3179.html', params=params, cookies=cookies,
#                                 headers=headers, proxies=proxies)
#     html = response.text
#     print(html)
# trash_sp()
# def tr_sp2():
#     import requests
#
#     response = requests.get(
#         'https://webresource.c-ctrip.com/res/concat?f=/ResADVOnline/R2/dist/sales/wakeup.v2.0.js?v=20221011201653,/ResADVOnline/R2/dist/sales/float.v2.0.js?v=20221011201653',
#     )
#     print(response.text)
# tr_sp2()
#
# def ultimate_trash():
#     # import requests
#     import requests
#
#     cookies = {
#         'MKT_CKID': '1678877641586.hgzy3.khw3',
#         'GUID': '09031061117395115814',
#         '_gcl_aw': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
#         '_gcl_dc': 'GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE',
#         '_bfaStatusPVSend': '1',
#         '_RSG': 'mtamLYXsaCDiVPY3UEFWb8',
#         '_RDG': '28bc646fcd610727d5191cdc509a6e59cb',
#         '_RGUID': 'd324da18-95c2-4df0-8960-3ce7838997ec',
#         'nfes_isSupportWebP': '1',
#         'ibulanguage': 'CN',
#         'ibulocale': 'zh_cn',
#         'cookiePricesDisplayed': 'CNY',
#         'intl_ht1': 'h4=2_445287',
#         'MKT_CKID_LMT': '1679092404462',
#         '_jzqco': '%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46',
#         '__zpspc': '9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23',
#         '_ga': 'GA1.2.1659888908.1679100096',
#         '_gid': 'GA1.2.1082757209.1679100096',
#         'ibu_h5_lang': 'en',
#         'ibu_h5_local': 'en-us',
#         'Hm_lvt_37b54c42b9dde393e60c88c1a84657cb': '1679100205',
#         'MKT_Pagesource': 'H5',
#         '_bfi': 'p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50',
#         '_bfaStatus': 'success',
#         '_RF1': '169.150.221.195',
#         'librauuid': '',
#         'MKT_OrderClick': 'ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679136388916&CURL=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgspoi%2Fsight%2F18254.html%3FisHideNavBar%3DYES%26seo%3D0%26allianceid%3D4899%26sid%3D155997%26isHideNavBar%3DYES%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fwebapp%252Fyou%252Fgsdestination%252Fplace%252F2.html%253Fseo%253D0%2526ishideheader%253Dtrue%2526secondwakeup%253Dtrue%2526dpclickjump%253Dtrue%2526allianceid%253D4899%2526sid%253D155997%2526from%253Dhttps%25253A%25252F%25252Fm.ctrip.com%25252Fhtml5%25252F&VAL={"h5_vid":"1678877639540.m3gjc"}',
#         'Union': 'OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679136390&Expires=1679741189507',
#         '_pd': '%7B%22_o%22%3A2%2C%22s%22%3A262%2C%22_s%22%3A1%7D',
#         'Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb': '1679137702',
#         '_bfa': '1.1678877639540.m3gjc.1.1678959020085.1679137702504.9.178.214062',
#         '_ubtstatus': '%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A9%2C%22pvid%22%3A178%2C%22pid%22%3A214062%7D',
#     }
#
#     headers = {
#         'authority': 'm.ctrip.com',
#         'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
#         'accept-language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6',
#         'cache-control': 'max-age=0',
#         # 'cookie': 'MKT_CKID=1678877641586.hgzy3.khw3; GUID=09031061117395115814; _gcl_aw=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _gcl_dc=GCL.1678877642.EAIaIQobChMIvPCCxuLd_QIVZCCtBh1b1wqBEAAYASAAEgKYDvD_BwE; _bfaStatusPVSend=1; _RSG=mtamLYXsaCDiVPY3UEFWb8; _RDG=28bc646fcd610727d5191cdc509a6e59cb; _RGUID=d324da18-95c2-4df0-8960-3ce7838997ec; nfes_isSupportWebP=1; ibulanguage=CN; ibulocale=zh_cn; cookiePricesDisplayed=CNY; intl_ht1=h4=2_445287; MKT_CKID_LMT=1679092404462; _jzqco=%7C%7C%7C%7C1679092408131%7C1.1439469229.1678877641584.1679099923188.1679099994962.1679099923188.1679099994962.undefined.0.0.46.46; __zpspc=9.3.1679092403.1679099994.33%231%7Cgoogleppc%7Cgoogle%7Cpp%7C%7C%23; _ga=GA1.2.1659888908.1679100096; _gid=GA1.2.1082757209.1679100096; ibu_h5_lang=en; ibu_h5_local=en-us; Hm_lvt_37b54c42b9dde393e60c88c1a84657cb=1679100205; MKT_Pagesource=H5; _bfi=p1%3D0%26p2%3D290510%26v1%3D102%26v2%3D50; _bfaStatus=success; _RF1=169.150.221.195; librauuid=; MKT_OrderClick=ASID=4899155997&AID=4899&CSID=155997&OUID=&CT=1679136388916&CURL=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgspoi%2Fsight%2F18254.html%3FisHideNavBar%3DYES%26seo%3D0%26allianceid%3D4899%26sid%3D155997%26isHideNavBar%3DYES%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fwebapp%252Fyou%252Fgsdestination%252Fplace%252F2.html%253Fseo%253D0%2526ishideheader%253Dtrue%2526secondwakeup%253Dtrue%2526dpclickjump%253Dtrue%2526allianceid%253D4899%2526sid%253D155997%2526from%253Dhttps%25253A%25252F%25252Fm.ctrip.com%25252Fhtml5%25252F&VAL={"h5_vid":"1678877639540.m3gjc"}; Union=OUID=&AllianceID=4899&SID=155997&SourceID=&createtime=1679136390&Expires=1679741189507; _pd=%7B%22_o%22%3A2%2C%22s%22%3A262%2C%22_s%22%3A1%7D; Hm_lpvt_37b54c42b9dde393e60c88c1a84657cb=1679137702; _bfa=1.1678877639540.m3gjc.1.1678959020085.1679137702504.9.178.214062; _ubtstatus=%7B%22vid%22%3A%221678877639540.m3gjc%22%2C%22sid%22%3A9%2C%22pvid%22%3A178%2C%22pid%22%3A214062%7D',
#         'if-none-match': '"46e3-k2pnxofAKmhPCYcX72ApkO/wbeQ"',
#         'referer': 'https://m.ctrip.com/webapp/you/gsdestination/place/3179.html?ishideheader=true&fromcitylist=yes&seo=0&from=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgsdestination%2Fplace%2F2.html%3Fseo%3D0%26ishideheader%3Dtrue%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fhtml5%252F',
#         'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
#         'sec-ch-ua-mobile': '?1',
#         'sec-ch-ua-platform': '"Android"',
#         'sec-fetch-dest': 'document',
#         'sec-fetch-mode': 'navigate',
#         'sec-fetch-site': 'same-origin',
#         'sec-fetch-user': '?1',
#         'upgrade-insecure-requests': '1',
#         'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36',
#     }
#
#     params = [
#         ('isHideNavBar', 'YES'),
#         ('seo', '0'),
#         ('isHideNavBar', 'YES'),
#         ('from',
#          'https://m.ctrip.com/webapp/you/gsdestination/place/3179.html?ishideheader=true&fromcitylist=yes&seo=0&from=https%3A%2F%2Fm.ctrip.com%2Fwebapp%2Fyou%2Fgsdestination%2Fplace%2F2.html%3Fseo%3D0%26ishideheader%3Dtrue%26from%3Dhttps%253A%252F%252Fm.ctrip.com%252Fhtml5%252F'),
#     ]
#
#
#
#     try:
#         response = requests.get('https://m.ctrip.com/webapp/you/gspoi/sight/3179.html', params=params, cookies=cookies,
#                                 headers=headers)
#     except:
#         proxies = {
#             'https': '127.0.0.1:7890'
#         }
#         response = requests.get('https://m.ctrip.com/webapp/you/gspoi/sight/3179.html', params=params, cookies=cookies,
#                                 headers=headers, proxies=proxies)
#     html = response.text
#     # html_file = ''
#     f = open('data_index.html', 'w+', encoding='utf-8')
#     f.write(html)
#     f.close()
#     print(html)
# ultimate_trash()